﻿//得到浏览器显示的屏幕高度
document.getViewportHeight = function(){
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
};
//得到浏览器显示的屏幕宽度
document.getViewportWidth = function(){
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
};
/**
 * 遮罩层，组件的显示及隐藏
 */
Shade_VB2005XU = {
	mask:null,
	container:null,
	isIE6:null,
	init:function(conf){
			//判断浏览器是否是ie6或其以下版本
			var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
			if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
				this.isIE6 =  true;
			}else{
				this.isIE6 = false;	
			}
			//将遮罩层加入body
			var popmask = document.createElement('div');
			popmask.id = 'mask';
			document.body.appendChild(popmask);
			this.mask = document.getElementById("mask");
			this.mask.style.display = "none" ;
			
			//将组件边框加入body
			var popcont = document.createElement('div');
			popcont.id = 'popupContainer';
			popcont.innerHTML ="<div id='popupInner'>"+
									"<div id='popupTitleBar'>"+
										"<div id='popupTitle'></div>"+
										"<div id='popupControls'>"+
										"<img src='/static/images/closebtn.gif' onclick='Shade_VB2005XU.hide();' id='popCloseBox' />"+
									"</div></div>"+
								"<div id='popupFrame'>dd</div>";
			document.body.appendChild(popcont);
			this.container = document.getElementById("popupContainer");
			this.container.style.display = "none" ;
			
			
			// 加载自定义设置的内容 -- by 色色 -- 这些应该属于初始化的内容
			
			//设置组件的标题
			document.getElementById('popupTitle').innerHTML = conf.title;
			//设置组件的长和宽
			this.container.style.width = conf.width+"px";
			this.container.style.height = conf.height+"px";
			var frame = document.getElementById('popupFrame');	
			frame.style.width = (conf.width -4)+"px";
			frame.style.height = (conf.height -31)+"px";
			
			//设置组件内容
			frame.innerHTML = conf.templete;
			
			this.render(conf);
			this.enDrag();
			
			var Shade_this = this ; //传递this参数,到浏览器窗体改变事件
			Shade_this.conf = conf ;
			
			window.onresize = function(){
				if (Shade_this.container) {
					Shade_this.render(Shade_this.conf);
				}
			} ;
	} ,
	/*增加拖动功能*/
	enDrag: function(){		
		var popupTitleBar = document.getElementById('popupTitleBar') ;
		popupTitleBar.style.cursor = "move" ;
		Drag.init(popupTitleBar,this.container);
	} ,
	render:function(conf){
		this.setMaskSize();
		this.toCenter(conf);
	} , 
	
	//设置遮罩层的长度和宽度
	setMaskSize:function(){
			var theBody = document.body;
			
			var fullHeight = document.getViewportHeight();
			var fullWidth = document.getViewportWidth();
			
			// Determine what's bigger, scrollHeight or fullHeight / width
			if (fullHeight > theBody.scrollHeight) {
				this.popHeight = fullHeight;
			} else {
				this.popHeight = theBody.scrollHeight;
			}
			
			if (fullWidth > theBody.scrollWidth) {
				this.popWidth = fullWidth;
			} else {
				this.popWidth = theBody.scrollWidth;
			}
			
			this.mask.style.height = this.popHeight + "px";
			this.mask.style.width = this.popWidth + "px";
	},
	toCenter:function(conf){
		var s = this.container.style;
		s.left = (document.getViewportWidth()-conf.width)/2+"px";
		s.top = (document.getViewportHeight()-conf.height)/4+"px";		
	},
	show:function(){
		//if ()
		this.container.style.display = this.mask.style.display = "" ;
	},
	hide:function(){
		//删除遮罩层
		document.body.removeChild(this.mask);
		//删除组件层
		document.body.removeChild(this.container);
	} 
} 
